﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Framework
{
    public class GlobalSettingsManager
    {
        static readonly object locker = new object();

        static GlobalSettingsManager instance;
        public static GlobalSettingsManager Instance
        {
            get
            {
                lock (locker)
                    if (instance == null)
                        instance = new GlobalSettingsManager();

                return instance;
            }
        }

        readonly object localLocker = new object();
        StableDiffusionToolsSettings settings;
        public StableDiffusionToolsSettings Settings
        {
            get
            {
                lock (localLocker)
                    if (settings == null)
                        settings = SettingsManager.LoadSettings();

                return settings;
            }
        }

        public SettingsManager<StableDiffusionToolsSettings> SettingsManager { get; } = new SettingsManager<StableDiffusionToolsSettings>(nameof(StableDiffusionToolsSettings), createBackups: false);

        public static StableDiffusionToolsSettings GetSettings()
        {
            return Instance.Settings;
        }

        public static void SaveSettings()
        {
            Instance.SettingsManager.SaveSettings(Instance.Settings);
        }
    }
}
